{
  "properties" : { },
  "id" : "8d289e6c1d2e4138801f34b6c1d7008f",
  "script" : null,
  "groupId" : "43da313fdeaa495798cf783e6cf83479",
  "name" : "新建分组或新增ip",
  "createTime" : 1727070851960,
  "updateTime" : 1726304701748,
  "lock" : "0",
  "createBy" : "ndmp",
  "updateBy" : "ndmp",
  "path" : "saveTree",
  "method" : "POST",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "{\"groupName\":\"ceshi\",\"isApp\":0,\"isManager\":1,\"isNet\":0,\"appRealTimeStartIp\":\"\",\"appRealTimeStopIp\":\"\",\"appNonRealTimeStartIp\":\"\",\"appNonRealTimeStopIp\":\"\",\"managerStartIp\":\"13.65.76.34\",\"managerStopIp\":\"13.65.76.76\",\"netStartIp\":\"\",\"netStopIp\":\"\",\"parentId\":\"\"}",
  "headers" : [ {
    "name" : "blade-auth",
    "value" : "bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJyb2xlX25hbWUiOiJhZG1pbmlzdHJhdG9yIiwicG9zdF9pZCI6IjExMjM1OTg4MTc3Mzg2NzUyMDEiLCJ1c2VyX2lkIjoiMTEyMzU5ODgyMTczODY3NTIwMSIsInJvbGVfaWQiOiIxMTIzNTk4ODE2NzM4Njc1MjAxIiwidXNlcl9uYW1lIjoiYWRtaW4iLCJuaWNrX25hbWUiOiLnrqHnkIblkZgiLCJkZXRhaWwiOnsidHlwZSI6IndlYiJ9LCJ0b2tlbl90eXBlIjoiYWNjZXNzX3Rva2VuIiwiZGVwdF9pZCI6IjE3OTM0OTQ0MTgwODMzMTk4MTAiLCJhY2NvdW50IjoiYWRtaW4iLCJjbGllbnRfaWQiOiJzYWJlciIsImV4cCI6MTcyNjA0NTA0MSwibmJmIjoxNzI2MDQxNDQxfQ.F6grFMPoqDGF2cNSL8uQ3hiFiH90x9_SPvvrz2XCa3ZtqCkaMi9-ZIvgVVkwPVgLuTk3K-Bwp56_dqtgI5tFMQ",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  } ],
  "paths" : [ ],
  "responseBody" : "{\n    \"status\": 200,\n    \"message\": \"success\",\n    \"data\": true\n}",
  "description" : "",
  "requestBodyDefinition" : {
    "name" : "",
    "value" : { },
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ ]
  },
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "String",
    "type" : "",
    "defaultValue" : "",
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "status",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "Hello magic-api",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : "",
      "defaultValue" : "",
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
import org.apache.commons.lang3.StringUtils
import java.util.UUID
import org.springblade.core.tool.api.R
import cn.hutool.core.net.Ipv4Util
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil
import redis

import "@/util/filtrationNetIpV2" as filtrationNetIpV2
import "@/util/getListIpCondition" as getListIpCondition
import "@/util/insertIpSourceData" as insertIpSourceData



/**
 * 管理地址 掩码
 */
var MANAGE_MASK = "32";
/**
 * 互联地址 掩码
 */
var NET_MASK = "30";
/**
 * 应用地址 掩码
 */
var APP_MASK = "26";
var token = header.get("blade-auth")::string;
var dccId = redis.get(token.substring(7))

var groupId
if (StringUtils.isEmpty(body.id)) { 
    groupId = UUID.randomUUID().toString().replaceAll("-", "");
    if (StringUtils.isEmpty(body.groupName)) {
        return R.fail("请输入分组名称");
    }

} else {
    //在已有的分组中添加ip
    groupId = body.id;
}


if (StringUtils.isEmpty(body.parentId)) {

    if ((StringUtils.isEmpty(body.managerStartIp) || StringUtils.isEmpty(body.managerStopIp)) and
        (StringUtils.isEmpty(body.netStartIp) || StringUtils.isEmpty(body.netStopIp)) and
        (StringUtils.isEmpty(body.appRealTimeStartIp) || StringUtils.isEmpty(body.appRealTimeStopIp)) and
        (StringUtils.isEmpty(body.appNonRealTimeStartIp) || StringUtils.isEmpty(body.appNonRealTimeStopIp))) {
        return R.fail("请输入ip范围");
    }
}

List managerIpList;
List netIpList = new ArrayList();
List appRealTimeIpList = new ArrayList();
List appNonRealTimeIpList = new ArrayList();

if (body.isManager == 1) {
    managerIpList = Ipv4Util.list(body.managerStartIp, body.managerStopIp);

    if (!StringUtils.isEmpty(body.parentId)) {

        List listParentIpMap = db.table("ndmp_ip_source_manager").where().eq("group_id", body.parentId).eq("ip_type", MANAGE_MASK).select()
        List listParentIp = new ArrayList()
        for (map in listParentIpMap) {

            listParentIp.add(map.get("ip"))
        }

        if (CollectionUtil.isEmpty(listParentIp)) {
            return R.fail("请在父级分组输入管理IP范围。");
        }

        for (ip in managerIpList) {
            if (!listParentIp.contains(ip)) {
                return R.fail("管理IP输入有误：" + ip + ",范围是" + listParentIp.get(0) +
                    "----" + listParentIp.get(listParentIp.size() - 1));
            }
        }
    }
} else {
    managerIpList = new ArrayList();
}

//互联地址从
if (body.isNet == 1) {
    List listIp = Ipv4Util.list(body.netStartIp, body.netStopIp);

    List list = new ArrayList();

    var ipSuffix = Integer.parseInt(listIp.get(listIp.size() - 1).substring(listIp.get(listIp.size() - 1).lastIndexOf(".") + 1))::int;

    for (i in range(0, ipSuffix)) {
        if (i % 4 == 0) {
            list.add(i);
        }

    }
    Set setIp = new HashSet();
    listIp.forEach(v -> {
        String ip = v.substring(0, v.lastIndexOf("."));
        setIp.add(ip);
    });

    for (ip in setIp) {
        for (ipLastPart in list) {
            List netIpListv = Ipv4Util.list(ip + "." + ipLastPart, 30, false);
            List resNet =
                netIpListv.stream().filter(v -> Integer.parseInt(v.substring(v.lastIndexOf(".") + 1)) % 2 == 0).collect(Collectors.toList());
            netIpList.addAll(resNet);
        }
    }


    if (!StringUtils.isEmpty(body.parentId)) {

        List listParentIpMap = db.table("ndmp_ip_source_manager").where().eq("group_id", body.parentId).eq("ip_Type", NET_MASK).select();
        List listParentIp = new ArrayList()
        for (map in listParentIpMap) {

            listParentIp.add(map.get("ip"))
        }


        if (CollectionUtil.isEmpty(listParentIp)) {
            return R.fail("请在父级分组输入互联IP范围。");
        }
        for (ip in netIpList) {
            if (!listParentIp.contains(ip)) {
                return R.fail("互联IP输入有误：" + ip + ",范围是" + listParentIp.get(0) + "----" + listParentIp.get(listParentIp.size() - 1));
            }
        }
    }
}

//应用地址
if (body.isApp == 1) {

    appRealTimeIpList = Ipv4Util.list(body.appRealTimeStartIp, body.appRealTimeStopIp);

    if (!StringUtils.isEmpty(body.parentId)) {

        List listParentIpMap = db.table("ndmp_ip_source_manager").where().eq("group_id", body.parentId).eq("ip_Type", APP_MASK).select();


        List listParentIp = new ArrayList()
        for (map in listParentIpMap) {

            listParentIp.add(map.get("ip"))
        }
        if (CollectionUtil.isEmpty(listParentIp)) {
            return R.fail("请在父级分组输入应用实时IP范围。");
        }
        for (ip in appRealTimeIpList) {

            if (!listParentIp.contains(ip)) {
                return R.fail("应用实时IP输入有误：" + ip + ",范围是" + listParentIp.get(0) + "----" + listParentIp.get(listParentIp.size() - 1));
            }
        }
    }

    appNonRealTimeIpList = Ipv4Util.list(body.appNonRealTimeStartIp, body.appNonRealTimeStopIp);
    if (!StringUtils.isEmpty(body.parentId)) {

        List listParentIpMap = db.table("ndmp_ip_source_manager").where().eq("group_id", body.parentId).eq("ip_Type", APP_MASK).select();
        List listParentIp = new ArrayList()
        for (map in listParentIpMap) {

            listParentIp.add(map.get("ip"))
        }

        List listParentIp = new ArrayList()
        for (map in listParentIpMap) {

            listParentIp.add(map.get("ip"))
        }
        if (CollectionUtil.isEmpty(listParentIp)) {
            return R.fail("请在父级分组输入应用非实时IP范围。");
        }
        for (ip in appNonRealTimeIpList) {

            if (!listParentIp.contains(ip)) {
                return R.fail("应用非实时实时IP输入有误：" + ip + ",范围是" + listParentIp.get(0) + "----" + listParentIp.get(listParentIp.size() - 1));
            }
        }
    }

}


List managerList = getListIpCondition(MANAGE_MASK, managerIpList, 99);
List netList = getListIpCondition(NET_MASK, netIpList, 99);
List appRealTimeList = getListIpCondition(APP_MASK, appRealTimeIpList, 1);
List appNonRealTimeList = getListIpCondition(APP_MASK, appNonRealTimeIpList, 0);


List resList = new ArrayList();
resList.addAll(managerList);
resList.addAll(netList);
resList.addAll(appRealTimeList);
resList.addAll(appNonRealTimeList);

async insertIpSourceData(groupId, resList)

if (StringUtils.isEmpty(body.id)) {
    body.id = groupId;
    body.dccId = dccId;

    db.table("ndmp_ip_group").insert(body);

} else {


    var vo = db.table("tableName").where.eq("id", groupId).select();


    if (body.isManager == 1) {
        vo.managerStartIp = vo.managerStartIp + "," + body.managerStartIp;
        vo.managerStopIp = vo.managerStopIp + "," + body.managerStopIp;
    }
    if (body.isNet == 1) {
        vo.netStartIp = vo.netStartIp + "," + body.netStartIp;
        vo.netStopIp = vo.netStopIp + "," + body.netStopIp;
    }
    if (body.isApp == 1) {
        vo.appNonRealTimeStartIp = vo.appNonRealTimeStartIp + "," + body.appNonRealTimeStartIp;
        vo.appNonRealTimeStopIp = vo.appNonRealTimeStopIp + "," + body.appNonRealTimeStopIp;

        vo.appRealTimeStartIp = vo.appRealTimeStartIp + "," + body.appRealTimeStartIp;
        vo.appRealTimeStopIp = vo.appRealTimeStopIp + "," + body.appRealTimeStopIp;
    }

    ipGroupMapper.updateById(vo);
}

return true